Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sm4-password

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sm4-password

hash password with sm4 algorithm

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

sm4-password

Node.js上的基于sm4算法的密码生成和验证扩展。

安装


npm i sm4-password

基本使用

'use strict'

const sm4pass = require('sm4-password')

let pass = new sm4pass()

//用于加密salt,不足16位会填充,超过则会截断。
pass.key = '1qazxs'

//生成的salt长度,默认为10,最大为20。
pass.saltLength = 9

let org_passwd = '111222ooo'

//生成hash password
let hash_passwd = pass.make(org_passwd)

//正确的验证和错误的验证对比
let vp = pass.verify(org_passwd, hash_passwd)
let vp_fail = pass.verify('222333', hash_passwd)

console.log(hash_passwd, vp, vp_fail)

make(passwd, encrypt = true)方法

make方法支持第二个参数为false表示不使用加密,此时生成的hash_password没有加密salt。

hashMap(salt, passwd)

hashMap接受一个函数类型的值,用于生成拼接后的字符串。可以设定自己的拼接方式:


pass.hashMap = (salt, passwd) => {
    return `${salt}-${passwd}`
}

Keywords

FAQs

Package last updated on 26 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc